package com.qf.sy2103.fmmall.api.controller;

import com.qf.sy2103.common.vo.ResStatus;
import com.qf.sy2103.common.vo.ResultVO;
import com.qf.sy2103.fmmall.beans.entity.Category;
import com.qf.sy2103.fmmall.beans.entity.IndexImg;
import com.qf.sy2103.fmmall.beans.vo.CategoryVo;
import com.qf.sy2103.fmmall.service.CategoryService;
import com.qf.sy2103.fmmall.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@CrossOrigin
@RestController
@RequestMapping("/index")
@Api(value = "首页控制器",tags = "首页控制器")
public class IndexController {

    @Autowired
    CategoryService categoryService;

    @Autowired
    ProductService productService;

    @RequestMapping(value = "/indeximg",method = RequestMethod.GET)
    public ResultVO indeximg(){

        final ResultVO resultVO = new ResultVO();

        final ArrayList<IndexImg> indexImgs = new ArrayList<>();
        final IndexImg indexImg = new IndexImg();
        indexImg.setImgUrl("ad5.jpg");
        indexImgs.add(indexImg);

        final IndexImg indexImg1 = new IndexImg();
        indexImg1.setImgUrl("ad3.jpg");
        indexImgs.add(indexImg1);

        resultVO.setCode(ResStatus.OK);
        resultVO.setData(indexImgs);
        resultVO.setMsg("success");

        return resultVO;

    }


    @GetMapping("/category-list")
    public ResultVO categorylist(){

        final ResultVO vo = categoryService.categorylist();
        return vo;


//        final ResultVO resultVO = new ResultVO();
//
//        final ArrayList<CategoryVo> categoryVos1 = new ArrayList<>();
//
//        final CategoryVo categoryVo1 = new CategoryVo();
//        categoryVo1.setCategoryName("蛋糕/点心");
//        categoryVo1.setCategoryIcon("cake.png");
//
//        // 准备当前一级分类下的二级分类数据
//        final ArrayList<CategoryVo> categoryVos2 = new ArrayList<>();
//        final CategoryVo categoryVo2_1 = new CategoryVo();
//        categoryVo2_1.setCategoryName("蛋糕");
//        final ArrayList<CategoryVo> categoryVos3 = new ArrayList<>();
//        final CategoryVo categoryVo3_1 = new CategoryVo();
//        categoryVo3_1.setCategoryName("蒸蛋糕");
//        final CategoryVo categoryVo3_2 = new CategoryVo();
//        categoryVo3_2.setCategoryName("脱水蛋糕");
//        categoryVos3.add(categoryVo3_1);
//        categoryVos3.add(categoryVo3_2);
//
//        categoryVo2_1.setCategories(categoryVos3);
//
//        final CategoryVo categoryVo2_2 = new CategoryVo();
//        categoryVo2_2.setCategoryName("点心");
//
//        categoryVos2.add(categoryVo2_1);
//        categoryVos2.add(categoryVo2_2);
//
//        categoryVo1.setCategories(categoryVos2);
//
//        for (int i=0;i<10;i++) {
//            categoryVos1.add(categoryVo1);
//        }
//
//        resultVO.setCode(ResStatus.OK);
//        resultVO.setData(categoryVos1);
//        resultVO.setMsg("success");
//        return resultVO;

    }

    @ApiOperation(value = "首页的推荐商品")
    @GetMapping("/list-recommends")
    public ResultVO listRecommends(){

//        return productService.listRecommendProducts();
       return productService.listRecommendProductsByTk();

    }

    @ApiOperation(value = "首页分类商品")
    @GetMapping("/category-recommends")
    public ResultVO categoryRecommends(){
        return productService.categoryRecommends();
    }

}
